import { MessageOptions, useMessage, useNotification } from 'naive-ui'

type ShowMessage = {
  info: (content: string, option?: MessageOptions) => void
  success: (content: string, option?: MessageOptions) => void
  warning: (content: string, option?: MessageOptions) => void
  error: (content: string, option?: MessageOptions) => void
}

type ShowNotification = {
  info: (title: string, content: string, duration?: number) => void
  success: (title: string, content: string, duration?: number) => void
  warning: (title: string, content: string, duration?: number) => void
  error: (title: string, content: string, duration?: number) => void
}

export function useNaiveUI() {
  const message = useMessage()
  const notification = useNotification()

  const showMessage: ShowMessage = {
    info: (content, option) => message.info(content, option),
    success: (content, option) => message.success(content, option),
    warning: (content, option) => message.warning(content, option),
    error: (content, option) => message.error(content, option)
  }

  const showNotification: ShowNotification = {
    info: (title, content, duration = 3000) =>
      notification.info({ title, content, duration }),
    success: (title, content, duration = 3000) =>
      notification.success({ title, content, duration }),
    warning: (title, content, duration = 3000) =>
      notification.warning({ title, content, duration }),
    error: (title, content, duration = 3000) =>
      notification.error({ title, content, duration })
  }

  return {
    showMessage,
    showNotification
  }
}
